package com.sgcc.ln.pmos.e_ln_personalcenter.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.ln.pmos.common.utils.DateUtils;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.e_ln_personalcenter.bean.PowerCurveBean;

public class PowerCurveAdapter extends BaseQuickAdapter<PowerCurveBean.DataBean, BaseViewHolder> {

    private Context mContext;
    private ItemBtnClickListener mItemBtnClickListener;

    public PowerCurveAdapter(Context context) {
        super(R.layout.item_powercurve);
        mContext = context;
    }

    public interface ItemBtnClickListener {
        void onBtnDeleteClick(int position, PowerCurveBean.DataBean bean);

        void onBtnEditClick(int position, PowerCurveBean.DataBean bean);

        void onBtnRatioClick(int position, PowerCurveBean.DataBean bean);
    }

    public void setItemBtnClickListener(ItemBtnClickListener itemBtnClickListener) {
        mItemBtnClickListener = itemBtnClickListener;
    }


    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, PowerCurveBean.DataBean bean) {
        baseViewHolder.setText(R.id.tv_curve_name, bean.getRatioName());
        baseViewHolder.setText(R.id.tv_name, bean.getConfigurePerson());
        baseViewHolder.setText(R.id.tv_time, TextUtils.isEmpty(bean.getUpdateDate()) ? "" : DateUtils.getStrng_to_Times_ymd_5(bean.getUpdateDate()));
        baseViewHolder.setText(R.id.tv_remark, bean.getRemark());
        baseViewHolder.getView(R.id.tv_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mItemBtnClickListener != null) {
                    mItemBtnClickListener.onBtnDeleteClick(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.tv_setRatio).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mItemBtnClickListener != null) {
                    mItemBtnClickListener.onBtnRatioClick(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.tv_edit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mItemBtnClickListener != null) {
                    mItemBtnClickListener.onBtnEditClick(getItemPosition(bean), bean);
                }
            }
        });
    }
}
